﻿using System;
using System.Collections.Generic;
using Android.App;
using Android.Content;
using Android.Widget;

namespace SCPAK2
{
    public class SelectOptionDialog : Dialog
    {
        public ListView listView;
        public List<string> data = new List<string>();
        public ArrayAdapter adapter;
        public List<Action> actions = new List<Action>();
        public SelectOptionDialog(Context context) : base(context)
        {
            SetContentView(Resource.Layout.optionslist);
            adapter = new ArrayAdapter(context, Resource.Layout.MyDialog, Resource.Id.message);
            listView = FindViewById<ListView>(Resource.Id.optionlist);
            listView.Adapter = adapter;
            listView.ItemClick += new EventHandler<AdapterView.ItemClickEventArgs>(click);
        }
        public void click(object obj, AdapterView.ItemClickEventArgs args)
        {
            if (args.Position < actions.Count)
            {
                new System.Threading.Thread(new System.Threading.ThreadStart(actions[args.Position])).Start();
            }
            else
            {
                Hide();
            }
        }
        public void Add(string title, Action action)
        {
            adapter.Add(title);
            actions.Add(action);

        }
        public void Clear()
        {
            adapter.Clear();
            actions.Clear();
        }

        public void setText(string t)
        {
            SetTitle(t);
        }
    }
}